This repository was archived by the owner on Jun 27, 2018. It is now read-only.
  
  
  
  
Added support for using custom HTTP clients #12
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
I have added support for using custom HTTP clients in a backward-compatible way. The way this works, is that I made an HTTP
Clientinterface, with two implementations:CurlClientandStreamClient. The code for these implementations was refactored out of the originalHTTPMessage::send()method.You can use the new
HTTPMessage::setHttpClient()method to inject any HTTP client that conforms to the aforementioned interface. If none is injected, theHTTPMessagechooses one for you, using a similar strategy found in the original class.I also improved the code for the
fopen-based client, since it was not handling the response data properly like cURL code was doing.Additional Changes
.editorconfigwith a basic PSR-compliant configuration.gitignorefor excluding composer files that should not be committedphpunit.xml.distfor configuring PHPUnit. To override this file in your own development environment, you can copy it tophpunit.xmland make changes.HTTPMessage,CurlClient, andStreamClientclasses.curl_execandfopenis not easy. I opted to use PHP's built-in server (with an object-oriented wrapper) to respond with canned results that I can test against. This setup worked fine in my Mac-based PHP environment, but I'm not sure how well it works in non-bash environments. Can be changed in the future, but wanted to be thorough on the tests.Test Output